package com.qlslylq.ad.sdk.rx.subscribers;

import com.qlslylq.ad.sdk.net.ResponseObject;

import io.reactivex.subscribers.ResourceSubscriber;

/**
 * ToDo:用于默认订阅
 */
public class Subscriber<T> extends ResourceSubscriber<T> {

    private OnNext nextListener;

    public Subscriber(OnNext nextListener) {
        this.nextListener = nextListener;
    }

    @Override
    protected void onStart() {
        request(1);
    }

    /**
     * 对错误进行统一处理
     * 隐藏ProgressDialog
     */
    @Override
    public void onError(Throwable e) {
        if (nextListener instanceof OnNextOnError) {
            ((OnNextOnError) nextListener).onError(new ResponseObject());
        }
    }

    @Override
    public void onComplete() {
    }

    @Override
    public void onNext(T t) {
        if (nextListener != null) {
            nextListener.onNext(t);
        }
    }
}